<script>
    Namespace.register("EBCMS.{$namespace}type");
    $(function(){
        EBCMS.{$namespace}type.refresh = function refresh(){
            EBCMS.CORE.api({
                queryParams:{
                    order:{
                        'sort':'desc',
                    },
                    model:'forms/forms',
                },
                tpl:'{$namespace}type-table',
                target:'#{$namespace}type_table',
                compileAfter:function(p){
                    var $lists = $(p.target).find('a.list-group-item');
                    $lists.click(function(){
                        $lists.removeClass('active');
                        $(this).addClass('active');
                    });
                }
            });
        };
        EBCMS.{$namespace}type.change_forms = function change_forms(forms_id){
            EBCMS.CORE.compile({
                tpl:'{$namespace}-box',
                target:'#{$namespace}_box',
                compileAfter:function(){
                    EBCMS.{$namespace}.forms_id = forms_id;
                    EBCMS.{$namespace}.refresh({
                        page:1,
                        where:{
                            forms_id:['eq',forms_id],
                        }
                    });
                }
            });
        };
        EBCMS.CORE.compile({
            tpl:'{$namespace}type-box',
            target:'#{$namespace}type_box',
            compileAfter:function(){
                EBCMS.{$namespace}type.refresh();
            }
        });
    });
</script>

<script id="{$namespace}type-box" type="text/html">
    <div class="header">
        <div class="btn-group pull-right">
            <button class="btn btn-primary" onclick="EBCMS.CORE.changemain('{:url('forms/forms/index')}');">管理</button>
        </div>
        <div class="header-title" onclick="EBCMS.{$namespace}type.refresh();">表单</div>
    </div>
    <div class="body" style="bottom:0px;">
        <div id="{$namespace}type_table" class="box"></div>
    </div>
</script>

<script id="{$namespace}type-table" type="text/html">
    <div class="list-group tree tree_first" style="border-top: 1px solid #ddd;border-right: 1px solid #ddd;border-bottom: 1px solid #ddd;">
        [[include '{$namespace}type-table-item' data]]
    </div>
</script>

<script id="{$namespace}type-table-item" type="text/html">
    [[each rows as v n]]
        <a class="list-group-item" href="javascript:EBCMS.{$namespace}type.change_forms('[[v.id]]');"><span class="badge">[[v.mark]]</span>[[v.title]]
            </a>
    [[/each]]
</script>